package com.inibb.app.service.admin.impl;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.inibb.app.dao.JpaGenericDao;
import com.inibb.app.dao.api.IDao;
import com.inibb.app.po.security.SaFunc;
import com.inibb.app.service.admin.ISaFunctionService;

@Transactional
@Service
public class SaFunctionServiceImpl implements ISaFunctionService {

	private static final long serialVersionUID = 1L;

	private IDao<SaFunc, Integer> dao;

	@PersistenceContext(unitName = "entityManager")
	private EntityManager entityManager ;
	
	@Autowired
	public void setEntityManagerFactory() {
		dao = new JpaGenericDao<SaFunc, Integer>(entityManager,SaFunc.class);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<SaFunc> searchFunction() {
		return dao.getAll();
	}

	@Override
	public void saveOrUpdate(SaFunc vo) {
		if(vo.getFuncId()==null)
			dao.persist(vo);
		else
			dao.merge(vo);
	}

	@Override
	public void delete(SaFunc vo) {
		dao.delete(vo.getFuncId());
	}

	@Override
	public void delete(Integer id) {
		dao.delete(id);
	}

	@Override
	public SaFunc getFunction(Integer id) {

		return dao.get(id);
	}
}
